home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 4251 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  40 lines

  1. Path: rain.fr!news
  2. From: Claude Leyo <leyo@mail.atlantic-line.fr>
  3. Newsgroups: comp.lang.c
  4. Subject: qsort with large files
  5. Date: Fri, 02 Feb 1996 23:00:28 -0800
  6. Organization: CSI InterNetNews site
  7. Message-ID: <3113080C.349E@mail.atlantic-line.fr>
  8. NNTP-Posting-Host: superman.atlantic-line.fr
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 2.0b5 (Win16; I)
  13.  
  14. I don't succeed trying to sort a large array of names in a structure
  15. when the array is >64K. Is there a limitation of qsort() ? Thanks for 
  16. help.
  17. abstract of the program following:
  18. struct name_list
  19.  { char      name[32];
  20.  } ;
  21. name_list  huge *ptrfirst, huge  *ptr;
  22. int sort_function( name_list huge *p1, name_list huge *p2)
  23. { return strcmp((( struct name_list *)p1)->name,
  24.         (( struct name_list *)p2)->name);
  25. }
  26. int main()
  27. { int i, nb_entries = 2050L;  // problem arises when nb > 2040
  28.   ptrfirst = (name_list *) farcalloc(nb_entries,sizeof(name_list));
  29.   if (ptrfirst==NULL) {printf("not enough main memory"); exit(-1); }
  30.   for (i=0,ptr=ptrfirst; i<nb_entries;i++,ptr++)
  31.   { strcpy(ptr->name,"           ");
  32.     strset(ptr->name,'a'+random(26));    // generate test data
  33.   }
  34.   qsort((name_list  *)ptrfirst,nb_entries,sizeof(name_list),
  35.   (int(*) (const void *, const void *)) sort_function);
  36.   for (i=0,ptr=ptrfirst; i<nb_entries;i++,ptr++)
  37.     printf("  %s \n", ptr->name);
  38.   return 0;
  39. }
  40.